home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung / Power-Programmierung (Tewi)(1994).iso / magazine / nan_news / toolkit / acctweek.prg < prev    next >
Text File  |  1991-08-15  |  4KB  |  112 lines

  1. /*
  2.  * File......: ACCTWEEK.PRG
  3.  * Author....: Jo W. French dba Practical Computing
  4.  * CIS ID....: 74731,1751
  5.  * Date......: $Date:   15 Aug 1991 23:02:38  $
  6.  * Revision..: $Revision:   1.2  $
  7.  * Log file..: $Logfile:   E:/nanfor/src/acctweek.prv  $
  8.  * 
  9.  * The functions contained herein are the original work of Jo W. French
  10.  * and are placed in the public domain.
  11.  *
  12.  * Modification history:
  13.  * ---------------------
  14.  *
  15.  * $Log:   E:/nanfor/src/acctweek.prv  $
  16.  * 
  17.  *    Rev 1.2   15 Aug 1991 23:02:38   GLENN
  18.  * Forest Belt proofread/edited/cleaned up doc
  19.  * 
  20.  *    Rev 1.1   14 Jun 1991 19:50:46   GLENN
  21.  * Minor edit to file header
  22.  * 
  23.  *    Rev 1.0   01 Apr 1991 01:00:28   GLENN
  24.  * Nanforum Toolkit
  25.  *
  26.  */
  27.  
  28. /*  $DOC$
  29.  *  $FUNCNAME$
  30.  *     FT_ACCTWEEK()
  31.  *  $CATEGORY$
  32.  *     Date/Time
  33.  *  $ONELINER$
  34.  *     Return accounting week data
  35.  *  $SYNTAX$
  36.  *     FT_ACCTWEEK( [ <dGivenDate> ], [ <nWeekNum> ] ) -> aDateInfo
  37.  *  $ARGUMENTS$
  38.  *     <dGivenDate> is any valid date in any date format.  Defaults
  39.  *     to current system date if not supplied.
  40.  *
  41.  *     <nWeekNum> is a number from 1 to 52 signifying a week.
  42.  *     Defaults to current week if not supplied.
  43.  *  $RETURNS$
  44.  *     A three element array containing the following data:
  45.  *
  46.  *        aDateInfo[1] - The year and week as a character string "YYYYWW"
  47.  *        aDateInfo[2] - The beginning date of the accounting week
  48.  *        aDateInfo[3] - The ending date of the accounting week
  49.  *  $DESCRIPTION$
  50.  *     FT_ACCTWEEK() returns an array containing data about the
  51.  *     accounting week containing the given date.
  52.  *
  53.  *     An accounting period has the following characteristics:
  54.  *
  55.  *     If the first week of the period contains 4 or more 'work'
  56.  *     days, it is included in the period; otherwise, the first
  57.  *     week was included in the prior period.
  58.  *
  59.  *     If the last week of the period contains 4 or more 'work'
  60.  *     days it is included in the period; otherwise, the last week
  61.  *     is included in the next period.  This results in 13 week
  62.  *     'quarters' and 4 or 5 week 'months'.  Every 5 or 6 years, a
  63.  *     'quarter' will contain 14 weeks and the year will contain 53
  64.  *     weeks.
  65.  *  $EXAMPLES$
  66.  *     // get info about accounting week containing 9/15/90
  67.  *     aDateInfo := FT_ACCTWEEK( CTOD("09/15/90") )
  68.  *     ? aDateInfo[1]   //  199037       (37th week)
  69.  *     ? aDateInfo[2]   //  09/09/90     beginning of week 37
  70.  *     ? aDateInfo[3]   //  09/15/90     end of week 37
  71.  *
  72.  *     // get info about accounting week 25 in year containing 9/15/90
  73.  *     aDateInfo := FT_ACCTWEEK( CTOD("09/15/90"), 25 )
  74.  *     ? aDateInfo[1]   //  199025
  75.  *     ? aDateInfo[2]   //  06/17/89   beginning of week 25
  76.  *     ? aDateInfo[3]   //  06/23/90   end of week 25
  77.  *  $SEEALSO$
  78.  *     FT_DATECNFG() FT_ACCTMONTH() FT_ACCTQTR() FT_ACCTYEAR()
  79.  *  $END$
  80. */
  81.  
  82. FUNCTION FT_ACCTWEEK(dGivenDate,nWeekNum)
  83.  
  84. LOCAL nTemp, lIsWeek, aRetVal
  85.  
  86. IF ! VALTYPE(dGivenDate) $ 'ND'
  87.   dGivenDate := DATE()
  88. ELSEIF VALTYPE(dGivenDate) == 'N'
  89.   nWeekNum := dGivenDate
  90.   dGivenDate := DATE()
  91. ENDIF
  92.  
  93. lIsWeek := IF(VALTYPE(nWeekNum) != 'N', .F., .T.)
  94.  
  95. aRetVal := FT_ACCTYEAR(dGivenDate)
  96.  
  97. IF lIsWeek
  98.   nTemp := INT( (aRetVal[3] - aRetVal[2]) / 7 ) + 1
  99.   nWeekNum := IF(nWeekNum > 0 .AND. nWeekNum <= nTemp , ;
  100.                              nWeekNum, nTemp)
  101.   dGivenDate := aRetVal[2] + (nWeekNum - 1) * 7
  102. ENDIF
  103.  
  104. aRetVal[1] += PADL(LTRIM(STR(INT( (dGivenDate - ;
  105.               aRetVal[2]) / 7 ) + 1, 2)), 2, '0')
  106. dGivenDate += ( 6 - FT_DAYTOBOW(dGivenDate) )  // end of week
  107. aRetVal[2] := dGivenDate - 6
  108. aRetVal[3] := dGivenDate
  109.  
  110. RETURN aRetVal
  111.  
  112.